package fitness;

import optimizers.ganeat.triangle.ConstantsTriangle;

public class TriangleFitness extends SquareFitness {
	@Override
	public double goal(int i, int firstPeak) {
		return ConstantsTriangle.height - ConstantsTriangle.height
				* ((i - firstPeak) % ConstantsTriangle.period)
				/ ConstantsTriangle.period;
	}

	@Override
	protected int closestCorner(int i, int firstPeak) {
		int distanceToLastCorner = (i - firstPeak) % ConstantsTriangle.period;
		if (distanceToLastCorner <= ConstantsTriangle.period / 2) {
			return i - distanceToLastCorner;
		} else {
			return i - distanceToLastCorner + ConstantsTriangle.period;
		}
	}

	@Override
	protected double getHeight() {
		return ConstantsTriangle.height;
	}
}
